package sskj.regulatory.presentation.screen.register

import isskj.regulatory.presentation.base_mvp.api.ApiPresenter
import sskj.regulatory.data.response.Response
import sskj.regulatory.domain.entity.user.UserEntity
import sskj.regulatory.domain.fetcher.result_listener.RequestType
import sskj.regulatory.domain.interactor.UserInteractor
import javax.inject.Inject

class RegisterMakePasPresenter @Inject constructor()
    : ApiPresenter<RegisterMakePasContract.View>(), RegisterMakePasContract.Presenter {

    private val registerSuccess = { it: Response ->
        view.hideLoading()
        when (it.success) {
            true -> view.registerOk()
            false -> view.registerError(it.msg)
        }
    }

    override fun register(userEntity: UserEntity) {
        view.showLoading()
        fetch(userInteractor.registerUser(userEntity), REGISTER, registerSuccess)
    }

    override fun onRequestError(errorCode: String?, errorMessage: String?) {
        view.hideLoading()
        view.registerError(errorMessage)
    }

}